﻿using AntMovement.Comm.Helper;
using AntMovement.Comm.Model;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.Comm
{
    /// <summary>
    /// 退出
    /// </summary>
    public class Exit : IChainedHandle
    {
        private Func<int, OutTimeModel> _query;
        public Func<int, OutTimeModel> Query => _query;
        private Func<int, bool, bool> _updateTime;
        public Func<int, bool, bool> UpdateTime => _updateTime;

        public Exit(Func<int, OutTimeModel> query, Func<int, bool, bool> updateTime)
        {
            _query = query;
            _updateTime = updateTime;
        }

        public void Execute(byte[] request, List<byte> respond)
        {
            respond.Add(request[2]);
            respond.Add(request[3]);
            respond.Add(request[4]);
            respond.Add(request[5]);
            respond.Add(3);
            respond.Add(0);
            respond.Add(0);
            respond.Add(0);
            respond.Add(request[10]);
            int id = BytesHelper.BytesToInt(request[2], request[3], request[4], request[5]);
            UpdateTime.Invoke(id, true);
        }
    }
}
